package com.ccsoft.atools.service;

import com.ccsoft.atools.dao.PermissionMapper;
import com.ccsoft.atools.model.Permission;
import com.ccsoft.atools.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper dao;

    @Override
    public int deleteByPrimaryKey(Integer iid) {
        return dao.deleteByPrimaryKey(iid);
    }

    @Override
    public Permission insert(Permission record) {
        if (isExist(record.getSid()) == true)
            throw new BusinessException("编号：" + record.getSid() + ",已经存在！");
        int ret = dao.insert(record);
        return record;
    }

    @Override
    public Permission insertSelective(Permission record) {
        if (isExist(record.getSid()) == true)
            throw new BusinessException("编号：" + record.getSid() + ",已经存在！");
        int ret = dao.insertSelective(record);
        return record;
    }

    @Override
    public Permission selectByPrimaryKey(Integer iid) {
        return dao.selectByPrimaryKey(iid);
    }

    @Override
    public Permission updateByPrimaryKeySelective(Permission record) {
        int ret = dao.updateByPrimaryKeySelective(record);
        return record;
    }

    @Override
    public Permission updateByPrimaryKey(Permission record) {
        int ret = dao.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public List<Permission> selectAll() {
        return dao.selectAll();
    }

    @Override
    public Permission selectBySid(String sid) {
        return dao.selectBySid(sid);
    }

    @Override
    public boolean isExist(String sid) {
        if (sid == null || sid.length() <= 0) return false;
        Permission record = dao.selectBySid(sid);
        return record == null ? false : true;
    }

}